<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>系统管理员初始化 - xyUser System</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.7.2/font/bootstrap-icons.css" rel="stylesheet">
    <link href="../styles/common.css" rel="stylesheet">
    <style>
        body {
            display: flex;
            align-items: center;
            justify-content: center;
            min-height: 100vh;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            margin: 0;
            padding: 20px;
        }

        .init-container {
            max-width: 550px;
            width: 100%;
            background: white;
            padding: 40px;
            border-radius: 16px;
            box-shadow: 0 15px 35px rgba(0, 0, 0, 0.1);
            backdrop-filter: blur(10px);
        }

        .init-header {
            text-align: center;
            margin-bottom: 40px;
        }

        .init-header .icon {
            width: 80px;
            height: 80px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            margin: 0 auto 20px;
            box-shadow: 0 8px 25px rgba(102, 126, 234, 0.3);
        }

        .init-header .icon i {
            font-size: 2.5rem;
            color: white;
        }

        .init-header h2 {
            color: #2c3e50;
            font-size: 2.2rem;
            font-weight: 700;
            margin-bottom: 15px;
            letter-spacing: -0.5px;
        }

        .init-header p {
            color: #666;
            font-size: 1.1rem;
            margin: 0;
        }

        .info-card {
            background: linear-gradient(135deg, #f8f9ff 0%, #e8f2ff 100%);
            border: 1px solid #e3f2fd;
            border-radius: 12px;
            padding: 25px;
            margin-bottom: 30px;
        }

        .info-card h5 {
            color: #1976d2;
            font-weight: 600;
            margin-bottom: 15px;
            display: flex;
            align-items: center;
        }

        .info-card h5 i {
            margin-right: 10px;
            font-size: 1.2rem;
        }

        .info-list {
            list-style: none;
            padding: 0;
            margin: 0;
        }

        .info-list li {
            padding: 8px 0;
            border-bottom: 1px solid #e8f4fd;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .info-list li:last-child {
            border-bottom: none;
        }

        .info-list li strong {
            color: #1976d2;
            font-weight: 600;
        }

        .btn-primary {
            width: 100%;
            padding: 15px;
            font-size: 1.1rem;
            font-weight: 600;
            border-radius: 10px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border: none;
            transition: all 0.3s ease;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .btn-primary:hover {
            transform: translateY(-2px);
            box-shadow: 0 8px 25px rgba(102, 126, 234, 0.4);
        }

        .btn-primary i {
            margin-right: 10px;
            font-size: 1.2rem;
        }

        .btn-outline-secondary {
            border-radius: 8px;
            padding: 10px 20px;
            font-weight: 500;
            transition: all 0.3s ease;
        }

        .btn-outline-secondary:hover {
            transform: translateY(-1px);
            box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
        }

        .result {
            margin-top: 25px;
            padding: 20px;
            border-radius: 12px;
            border: none;
        }

        .success {
            background: linear-gradient(135deg, #d4edda 0%, #c3e6cb 100%);
            color: #155724;
            border-left: 4px solid #28a745;
        }

        .error {
            background: linear-gradient(135deg, #f8d7da 0%, #f5c6cb 100%);
            color: #721c24;
            border-left: 4px solid #dc3545;
        }

        .result h5 {
            display: flex;
            align-items: center;
            margin-bottom: 15px;
        }

        .result h5 i {
            margin-right: 10px;
            font-size: 1.3rem;
        }

        @media (max-width: 768px) {
            .init-container {
                margin: 20px;
                padding: 30px;
            }
            
            .init-header h2 {
                font-size: 1.8rem;
            }

            .init-header .icon {
                width: 60px;
                height: 60px;
            }

            .init-header .icon i {
                font-size: 2rem;
            }
        }
    </style>
</head>
<body>
    <div class="init-container">
        <div class="init-header">
            <div class="icon">
                <i class="bi bi-person-gear"></i>
            </div>
            <h2>系统管理员初始化</h2>
            <p class="text-muted">设置您的第一个管理员账号</p>
        </div>
        
        <div class="info-card">
            <h5><i class="bi bi-info-circle"></i>默认管理员信息</h5>
            <ul class="info-list">
                <li>
                    <span>用户名</span>
                    <strong>admin</strong>
                </li>
                <li>
                    <span>密码</span>
                    <strong>admin123</strong>
                </li>
                <li>
                    <span>权限级别</span>
                    <strong>系统管理员</strong>
                </li>
            </ul>
        </div>
        
        <div class="d-grid">
            <button id="initAdminBtn" class="btn btn-primary">
                <i class="bi bi-plus-circle"></i>
                创建系统管理员
            </button>
        </div>
        
        <div id="result" class="result" style="display: none;"></div>
        
        <div class="mt-4 text-center">
            <a href="login.html" class="btn btn-outline-secondary">
                <i class="bi bi-arrow-left me-2"></i>
                返回登录页面
            </a>
        </div>
    </div>

    <script>
        document.getElementById('initAdminBtn').addEventListener('click', async function() {
            const resultDiv = document.getElementById('result');
            resultDiv.style.display = 'none';
            
            try {
                const response = await fetch('/users/init-admin', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json'
                    }
                });
                
                const data = await response.json();
                
                resultDiv.innerHTML = `
                    <h5><i class="bi bi-check-circle"></i>${data.message}</h5>
                    <p>用户名: <strong>${data.username}</strong></p>
                    ${data.password ? `<p>密码: <strong>${data.password}</strong></p>` : ''}
                    <p>现在您可以 <a href="login.html" class="alert-link">登录</a> 系统了。</p>
                `;
                
                resultDiv.className = 'result success';
                resultDiv.style.display = 'block';
                
            } catch (error) {
                console.error('初始化管理员失败:', error);
                
                resultDiv.innerHTML = `
                    <h5><i class="bi bi-exclamation-triangle"></i>初始化管理员失败</h5>
                    <p>请稍后再试或联系技术支持。</p>
                `;
                
                resultDiv.className = 'result error';
                resultDiv.style.display = 'block';
            }
        });
    </script>
</body>
</html>